package com.fatmeraid.controller.farmerApplication;

import com.fatmeraid.common.model.PageResult;
import com.fatmeraid.common.result.Result;
import com.fatmeraid.domain.FarmerApplication;
import com.fatmeraid.service.FarmerApplicationService;
import com.fatmeraid.vo.PaginationVo;
import com.fatmeraid.vo.farmerApplication.AuditVo;
import com.fatmeraid.vo.farmerApplication.RegistrationVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "农户申请管理")
@RestController
@RequestMapping("/farmerApplication")
public class FarmerApplicationController {

	@Autowired
	private FarmerApplicationService FarmerApplicationService;
	@Operation(summary = "农户申请")
	@PostMapping
	public Result<Integer> submitApplication(@RequestBody RegistrationVo registrationVo){
		Integer result = FarmerApplicationService.submitApplication(registrationVo);
		return Result.ok(result);
	}


	@Operation(summary = "审核农户申请")
	@PutMapping("/audit")
	public Result<String> auditApplication(@RequestBody AuditVo auditVo){
		boolean result = FarmerApplicationService.auditApplication(auditVo);
		return Result.ok();
	}

	@Operation(summary = "获取农户申请列表")
	@GetMapping("/list")
	public Result<PageResult<FarmerApplication>> getFarmerApplicationList(PaginationVo paginationVo){
		PageResult<FarmerApplication> list = FarmerApplicationService.getFarmerApplicationList(paginationVo);
		return Result.ok(list);
	}

	@Operation(summary = "根据id获取农户申请详情")
	@GetMapping("/{id}")
	public Result<FarmerApplication> getFarmerApplicationById(@PathVariable Long id){
		FarmerApplication farmerApplication = FarmerApplicationService.getFarmerApplicationById(id);
		return Result.ok(farmerApplication);
	}


}
